package tasks

import (
	"fmt"
	"gin-mvc/pkg/setting"
	"github.com/robfig/cron"
	"time"
)

func Setup() {
	if setting.CronSetting.Enable {
		start()
	}
}

func start() {
	fmt.Printf("[%s]定时任务已开启...\n", setting.AppSetting.AppName)

	c := cron.New()
	c.AddFunc("* * * * * *", TestTask)
	c.Start()

	t1 := time.NewTimer(time.Second * 10)
	for {
		select {
		case <-t1.C:
			t1.Reset(time.Second * 10)
		}
	}
}
